package com.mujin.keji.collectionsystem.module.login.views;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.mujin.keji.collectionsystem.CcsApplication;
import com.mujin.keji.collectionsystem.Constant;
import com.mujin.keji.collectionsystem.R;
import com.mujin.keji.collectionsystem.common.CommonPagerAdapter;
import com.mujin.keji.collectionsystem.utils.SPUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 闪屏页面
 *
 * @author weishixiong
 * @Time 2018-05-23
 */
public class SplashActivity extends AppCompatActivity {
    private ViewPager viewPager;
    private View view;
    int[] photos = new int[]{R.drawable.image_welcome_one, R.drawable.image_welcome_two, R.drawable.image_welcome_three, R.drawable.image_welcome_four};
    private List<View> viewList;
    private CommonPagerAdapter commonPagerAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        CcsApplication.addActivity(this);
        requestWindowFeature(Window.FEATURE_NO_TITLE);// 隐藏标题
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);// 设置全屏
        setContentView(R.layout.activity_splash);
        SPUtil.putData(Constant.SP.CONSTANT, Constant.SP.ISCOMIN, true);
        viewPager = (ViewPager) findViewById(R.id.viewPager);
        viewList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            view = LayoutInflater.from(this).inflate(R.layout.layout_splash, null, false);
            ImageView ivSplash = (ImageView) view.findViewById(R.id.iv_splash);
            TextView tvStartUser = (TextView) view.findViewById(R.id.tv_start_user);
            ivSplash.setImageResource(photos[i]);
            viewList.add(view);
            if (i < 3) {
                tvStartUser.setVisibility(View.GONE);
            } else {
                tvStartUser.setVisibility(View.VISIBLE);
                tvStartUser.setOnClickListener(
                        new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                startActivity(new Intent(SplashActivity.this, LoginActivity.class));
                                finish();
                            }
                        });
            }
        }
        commonPagerAdapter = new CommonPagerAdapter(viewList);
        viewPager.setAdapter(commonPagerAdapter);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        CcsApplication.removeActivity(this);
    }
}
